# -*- coding: utf-8 -*-
"""
Created on Fri Mar 20 11:34:21 2020

@author: Administrator
"""


import requests
import sys
import io

#sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码
session = requests.Session()
#登录后才能访问的网页
#url = 'http://srm.nepstar.cn/ELSServer_HWXC/default2.jsp?account=110829_1001&loginChage=N&telphone1=18279409642'
url = 'http://srm.nepstar.cn/ELSServer_HWXC/rest/reportForm/SalesOutSourcingInfoService/salesOutSourcingInfosBySupplier'
#浏览器登录后得到的cookie，也就是刚才复制的字符串
cookie_str = r'rememberPwd=true; JSESSIONID=AC2326D501B51849DA0FFC0EBA01EF1E; autoLogin=true; uid=wATJkA4UNm-YZWcfYs1q5s1aNipnavdiC5DDAOx9UH2W0jH7ESqbctcRQxzCYm6yvmfMJj0l7O-aBthoAJfB_Kwm9q3-QzzLVpHxtCiIE71ix9KbM-0_gsYc3UuZiyWB'

#把cookie字符串处理成字典，以便接下来使用
cookies = {}
for line in cookie_str.split(';'):
    key, value = line.split('=', 1)
    cookies[key] = value

#设置请求头
headers = {'User-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}

#在发送get请求时带上请求头和cookies
resp = requests.get(url, headers = headers, cookies = cookies)
    
print(resp.content.decode('utf-8'))

data = {
        "elsAccount": "299386",
        "materialNumbers": "8074221,8074222,8074223,8074224,8074225,8074226,8074227,8074228,8074229,8074231,8074232,8074233,8074234,8074235,8074236,8074237,8074238,8074239,8074240,8074241,8074242,8074243,8075947,8080598,8081018,8089656,8095606,8095655,8097773,8100169,8100170,8100181,8100182,8100183,8100184",
        "startDateStr": "2020-03-01",
        "endDateStr": "2020-03-19",
        "type": "2",
        "area": "BJ02",
        "currentPage": 1,
        "pageSize": "50"
        }
    #req = session.post(url,data = data).text
    #html = etree.HTML(req)








